const _ = require("lodash");
const groupData = require("./group.js");

// 定义目标数字集合（1 到 49）
const targetSet = new Set(Array.from({ length: 49 }, (_, i) => (i + 1).toString()));

// 遍历每个分组
Object.entries(groupData).forEach(([groupName, groups]) => {
  // 展开并排序数字，转换为数字类型后进行比较
  const flattenedSorted = _.sortBy(_.flatten(groups), num => parseInt(num));

  // 创建当前分组的数字集合，转换为数字以便正确比较
  const presentNumbersSet = new Set(flattenedSorted.map(num => parseInt(num)));

  // 计算缺失的数字
  const missingNumbers = Array.from(targetSet).filter(num => !presentNumbersSet.has(parseInt(num)));
  
  // 计算多余的数字
  const numberCounts = _.countBy(flattenedSorted);
  const extraNumbers = Object.keys(numberCounts).filter(num => numberCounts[num] > 1);

  // 如果该分组存在缺失的或多余的数字，输出异常
  if (missingNumbers.length > 0 || extraNumbers.length > 0) {
    console.log(`异常分组: ${groupName}`);
    if (missingNumbers.length > 0) {
      console.log(`  缺少的数字: ${missingNumbers.join(', ')}`);
    }
    if (extraNumbers.length > 0) {
      console.log(`  多余的数字: ${extraNumbers.join(', ')}`);
    }
    console.log('----------------------------------------');
  }
});
